
function loadAll(){

    $('.alert').delay(2000).fadeOut(1000);

    $('#newPost').click(function(){

        var userId = $('#userId');
        var threadId = $('#threadId');
        var text = $('#new-textarea');

        $.ajax({

            type    : 'POST',
            url     : '../../posts/addPost',
            data    : {user: userId.val(), thread: threadId.val(), text: text.val()},
            success : function(){

                text.val('');
                location.reload();
            }
        })
    });

    $('.edit-post').click(function(){

        var ref = $(this).attr('itemref');

        $('#postId').attr('value', ref);
        $('#edit-textarea').val($('#post' + ref + '-text').html())
    });

    $('#editPost').click(function(){

        var postId = $('#postId');
        var text = $('#edit-textarea');

        $.ajax({

            type    : 'POST',
            url     : '../../posts/editPost',
            data    : {post: postId.val(), text: text.val()},
            success : function(){

                text.val('');
                location.reload();
            }
        })
    });

    $('.delete-post').click(function(){

        var post = $(this).attr('itemref');
        var thread = $(this).attr('threadref')

        var c = confirm($(this).attr('itemconfirm'));

        if(c){

            $.ajax({

                type    : 'POST',
                url     : '../../posts/deletePost',
                data    : {post: post, thread: thread},
                success : function(){

                    location.reload();
                }
            })
        }

    });
}